#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2021/9/17 17:08
# @Author : lenovo
# @Email : 26541796406@qq.com
# @File : choose_adress_page.py
# @Project : mryx_test
"""选择收货地址页面"""
from appium.webdriver.common.mobileby import MobileBy as By
from page.base_page import BasePage
class ChooseAdress(BasePage):
    """选择收获地址类"""
    """定位器"""
    add_adress_locator = (By.ID,'cn.missfresh.application:id/tv_title_bar_right_txt')  # 新增地址
    consignee_locator = (By.ID,'cn.missfresh.application:id/et_edit_address_receiver')  # 收货人
    mobile_phone_locator = (By.ID,'cn.missfresh.application:id/et_edit_address_tel')  # 手机号码
    adress1_locator = (By.ID,'cn.missfresh.application:id/tv_edit_detail_address')  # 第一个收货地址
    adress2_locator = (By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.' 
                             'FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.'
                             'LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.'
                             'LinearLayout/android.widget.LinearLayout/android.widget.TextView[2]')  # 第二个收货地址搜索框
    adress3_locator = (By.ID,'cn.missfresh.application:id/et_search_address_input')  # 最后一个收货地址搜索框
    no1_locator = (By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.'
                             'FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.'
                             'LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.'
                             'FrameLayout/android.widget.RelativeLayout/android.widget.ListView/android.widget.'
                             'FrameLayout[1]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.'
                             'TextView[1]')  # 选择搜索内容第一个
    flor_locator = (By.ID,'cn.missfresh.application:id/et_edit_doorplate') # 楼层门牌
    submit_locator = (By.ID,'cn.missfresh.application:id/btn_save_address') # 保存并使用
    tect_locator = (By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout'
                          '/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.'
                          'widget.LinearLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.'
                          'LinearLayout/android.widget.LinearLayout[2]/android.widget.RelativeLayout[1]/android.widget'
                          '.TextView[2]')  # 收货人姓名
    adress_text_locator = (By.ID,'cn.missfresh.application:id/tv_title_bar_center_txt')  # 新增地址文本
    def add_adress(self):
        """点击新增地址"""
        self.driver.find_element(*self.add_adress_locator).click()
    def clear_consignee(self):
        """清空收货人"""
        self.driver.find_element(*self.consignee_locator).clear()
    def input_consignee(self,consignee):
        """输入收货人"""
        self.driver.find_element(*self.consignee_locator).send_keys(consignee)
    def clear_mobile_phone(self):
        """清空手机号码"""
        self.driver.find_element(*self.mobile_phone_locator).clear()
    def input_mobile_phone(self,mobile_phone):
        """输入手机号码"""
        self.driver.find_element(*self.mobile_phone_locator).send_keys(mobile_phone)
    def click_adress1(self):
        """点击第一个收货地址输入框"""
        self.driver.find_element(*self.adress1_locator).click()
    def click_adress2(self):
        """点击第二个收货地址输入框"""
        self.driver.find_element(*self.adress2_locator).click()
    def click_adress3(self):
        """点击第三个收货地址输入框"""
        self.driver.find_element(*self.adress3_locator).click()
    def input_adress(self,adress):
        """输入收货地址"""
        self.driver.find_element(*self.adress3_locator).send_keys(adress)
    def click_no1(self):
        """选择第一个搜索出来的位置"""
        self.driver.find_element(*self.no1_locator).click()
    def input_flor(self,flor):
        """输入楼层门牌"""
        self.driver.find_element(*self.flor_locator).send_keys(flor)
    def submit(self):
        """点击保存并使用"""
        self.driver.find_element(*self.submit_locator).click()
    def get_text(self):
        """获取收货人姓名"""
        return self.driver.find_element(*self.tect_locator).text
    def get_adress_text(self):
        """获取新增地址文本"""
        return self.driver.find_element(*self.adress_text_locator).text